Add source generator for numeric wrapper boilerplate (#24)#25
Merged
Conversation
Introduces [NumericWrapper] attribute and a Roslyn IIncrementalGenerator that emits the equality, comparison, operator, conversion, and Create factory boilerplate for numeric strong-type wrappers. LINQ-style Min/Max are always generated; Sum is opt-in via GenerateSum = true. Migrates Positive<T>, NonNegative<T>, Negative<T>, and NonPositive<T> from ~100 lines each to a single file with just the type-specific validation and storage. SumExtensions.cs collapses into per-type generated extensions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
KaliCZ
added a commit
that referenced
this pull request
Apr 17, 2026
The main csproj has an Analyzer ProjectReference to StrongTypes.SourceGenerators. With --no-build, pack still needs to resolve project references and invokes the Build target on the generator project, which then fails with NETSDK1085 because NoBuild is set. Letting pack perform a (no-op incremental) build sidesteps this. The Pack step only runs on main pushes, so PR CI never exercised it — both #25 and #26 merged green and broke main. A follow-up should make this fail fast in PR CI. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
KaliCZ
added a commit
that referenced
this pull request
Apr 17, 2026
The main csproj has an Analyzer ProjectReference to StrongTypes.SourceGenerators. With --no-build, pack still needs to resolve project references and invokes the Build target on the generator project, which then fails with NETSDK1085 because NoBuild is set. Letting pack perform a (no-op incremental) build sidesteps this. The Pack step only runs on main pushes, so PR CI never exercised it — both #25 and #26 merged green and broke main. A follow-up should make this fail fast in PR CI. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StrongTypes.SourceGeneratorsproject (netstandard2.0) with anIIncrementalGeneratorthat emitsIEquatable/IComparable/operator/conversion/Createboilerplate for types marked[NumericWrapper], plusMin/Maxextensions always andSumopt-in viaGenerateSum = true.[NumericWrapper]attribute added to the library; the generator detects targets by full metadata name so it works for both generic wrappers (Positive<T>) and concrete types (e.g. a user-definedPageSize).Positive,NonNegative,Negative, andNonPositivemigrated from ~100 lines of boilerplate each to a thin file containing only the validation logic, storage strategy, and invariant description.SumExtensions.csis replaced by per-type generated extensions.analyzers/dotnet/csofKalicz.StrongTypes.nupkg, so consumers get the generator automatically.Resolves #24.
Test plan
dotnet test src/StrongTypes.Tests— 427/427 passingdotnet build StrongTypes.slnx— full solution buildsdotnet pack src/StrongTypes— NuGet package includesanalyzers/dotnet/cs/StrongTypes.SourceGenerators.dll🤖 Generated with Claude Code